package com.deyuanyun.pic.settings.task;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.quartz.DateBuilder;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 *  任务管理需要的实体类
 *  @author axiao(xj08.dream@gmail.com)
 *  @date 2016-08-03
 *  @version 1.0
 *  Histroy: [修改人][时间][描述]
 */
public class SchedulerJob implements Serializable {

    private static final long serialVersionUID = -5284150979705620023L;

    private String name;//任务名

    private String group; //任务组名

    private String desc; //描述

    private String jobState;//任务状态

    private String cron; //cron表达式

    private Date nextTime; //下次执行的时间

    private Date prevTime; //上次执行的时间

    private Date endTime;//任务结束时间

    private String timeZone;//任务对应的时区

    private Date startTime;//设置任务需要在哪个日期执行,如果Trigger为SimpleTrigger仅执行一次

    private Map<String, Object> dataMap;//任务执行需要的data

    private Class clazz;//任务执行需要的类

    private Integer endCount;//重复次数

    private int timeInterval;//时间间隔

    private DateBuilder.IntervalUnit intervalUnit;//重复规则

    public SchedulerJob() {
    }

    /**
     * cron表达式任务构建
     * @param name 任务名
     * @param group 任务组名
     * @param clazz 任务执行类
     * @param cron cron表达式
     */
    public SchedulerJob(String name, String group, Class clazz, String cron) {
        this.name = name;
        this.group = group;
        this.clazz = clazz;
        this.cron = cron;
    }

    /**
     * cron表达式任务构建
     * @param name 任务名
     * @param group 任务组名
     * @param clazz 任务执行类
     * @param cron cron表达式
     * @param dataMap 任务执行时的数据
     */
    public SchedulerJob(String name, String group, Class clazz, String cron, Map<String, Object> dataMap) {
        this.name = name;
        this.group = group;
        this.clazz = clazz;
        this.cron = cron;
        this.dataMap = dataMap;
    }

    /**
     * 单次任务构建
     * @param name 任务名
     * @param group 任务组名
     * @param startTime 任务执行的时间
     * @param clazz 任务执行类
     */
    public SchedulerJob(String name, String group, Date startTime, Class clazz) {
        this.name = name;
        this.group = group;
        this.startTime = startTime;
        this.clazz = clazz;
    }

    /**
     * 单次任务构建
     * @param name 任务名
     * @param group 任务组名
     * @param startTime 任务执行的时间
     * @param clazz 任务执行类
     * @param dataMap 任务执行时的数据
     */
    public SchedulerJob(String name, String group, Date startTime, Class clazz, Map<String, Object> dataMap) {
        this.name = name;
        this.group = group;
        this.startTime = startTime;
        this.clazz = clazz;
        this.dataMap = dataMap;
    }

    /**
     * 构建日历任务
     * @param name 任务名
     * @param group 任务组名
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param clazz 任务执行的类
     * @param endCount 重复次数
     * @param intervalUnit 时间间隔
     * @param timeInterval 重复规则
     */
    public SchedulerJob(String name, String group, Date startTime, Date endTime, Class clazz, Integer endCount,
                         DateBuilder.IntervalUnit intervalUnit, int timeInterval) {
        this.name = name;
        this.group = group;
        this.startTime = startTime;
        this.endTime = endTime;
        this.clazz = clazz;
        this.endCount = endCount;
        this.intervalUnit = intervalUnit;
        this.timeInterval = timeInterval;
    }

    /**
     * 构建日历任务
     * @param name 任务名
     * @param group 任务组名
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param clazz 任务执行的类
     * @param endCount 重复次数
     * @param intervalUnit 时间间隔
     * @param timeInterval 重复规则
     * @param dataMap 任务执行时的数据
     */
    public SchedulerJob(String name, String group, Date startTime, Date endTime, Class clazz, Integer endCount,
                       DateBuilder.IntervalUnit intervalUnit, int timeInterval, Map<String, Object> dataMap) {
        this.name = name;
        this.group = group;
        this.startTime = startTime;
        this.endTime = endTime;
        this.clazz = clazz;
        this.endCount = endCount;
        this.intervalUnit = intervalUnit;
        this.timeInterval = timeInterval;
        this.dataMap = dataMap;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getJobState() {
        return jobState;
    }

    public void setJobState(String jobState) {
        this.jobState = jobState;
    }

    public String getCron() {
        return cron;
    }

    public void setCron(String cron) {
        this.cron = cron;
    }

    public Date getNextTime() {
        return nextTime;
    }

    public void setNextTime(Date nextTime) {
        this.nextTime = nextTime;
    }

    public Date getPrevTime() {
        return prevTime;
    }

    public void setPrevTime(Date prevTime) {
        this.prevTime = prevTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getTimeZone() {
        return timeZone;
    }

    public void setTimeZone(String timeZone) {
        this.timeZone = timeZone;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Map<String, Object> getDataMap() {
        return dataMap;
    }

    public void setDataMap(Map<String, Object> dataMap) {
        this.dataMap = dataMap;
    }

    public Class getClazz() {
        return clazz;
    }

    public void setClazz(Class clazz) {
        this.clazz = clazz;
    }

    public Integer getEndCount() {
        return endCount;
    }

    public void setEndCount(Integer endCount) {
        this.endCount = endCount;
    }

    public int getTimeInterval() {
        return timeInterval;
    }

    public void setTimeInterval(int timeInterval) {
        this.timeInterval = timeInterval;
    }

    public DateBuilder.IntervalUnit getIntervalUnit() {
        return intervalUnit;
    }

    public void setIntervalUnit(DateBuilder.IntervalUnit intervalUnit) {
        this.intervalUnit = intervalUnit;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("name", name)
                .append("group", group)
                .append("desc", desc)
                .append("jobState", jobState)
                .append("cron", cron)
                .append("nextTime", nextTime)
                .append("prevTime", prevTime)
                .append("endTime", endTime)
                .append("timeZone", timeZone)
                .append("startTime", startTime)
                .append("dataMap", dataMap)
                .append("clazz", clazz)
                .append("endCount", endCount)
                .append("timeInterval", timeInterval)
                .append("intervalUnit", intervalUnit)
                .toString();
    }
}
